package net.slteam.base;

import java.io.Serializable;

/**
 * @author calm
 */
@SuppressWarnings("unused")
public class SLRunTimeError extends RuntimeException implements Serializable, IError {

    private static final long serialVersionUID = 1L;

    Integer code;

    String domain = DOMAIN_SLTEAM;

    String message;

    public SLRunTimeError() {
    }

    public SLRunTimeError(Throwable cause) {
        super(cause);
    }

    public SLRunTimeError(String message) {
        this.message = message;
    }
    
    public SLRunTimeError(String message, String... messages) {
        this.message = message;
        
        String temp = "";
        for (String msg : messages) {
            temp += msg + "|";
        }
        if (temp.length() > 0) {
            temp = temp.substring(0, temp.length() - 1);
            temp = "[" + temp + "]";
        }
        this.message += temp;
    }
    
    public SLRunTimeError(IError error) {
        domain = DOMAIN_SLTEAM;
        code = error.getCode();
        message = error.getMessage();
    }

    /**
     * Constructs a new runtime exception with {@code null} as its
     * detail message.  The cause is not initialized, and may subsequently be
     * initialized by a call to {@link #initCause}.
     */
    public SLRunTimeError(Integer code,
                          String domain,
                          String message) {
        this.code = code;
        this.domain = domain;
        this.message = message;
    }

    public static SLRunTimeErrorBuilder builder() {
        return new SLRunTimeErrorBuilder();
    }

    @Override
    public Integer getCode() {
        return this.code;
    }

    public void setCode(final Integer code) {
        this.code = code;
    }

    @Override
    public String getDomain() {
        return this.domain;
    }

    public void setDomain(final String domain) {
        this.domain = domain;
    }

    @Override
    public String getMessage() {
        return this.message;
    }

    public void setMessage(final String message) {
        this.message = message;
    }

    @Override
    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof SLRunTimeError)) {
            return false;
        } else {
            SLRunTimeError other = (SLRunTimeError) o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                label47:
                {
                    Object this$code = this.getCode();
                    Object other$code = other.getCode();
                    if (this$code == null) {
                        if (other$code == null) {
                            break label47;
                        }
                    } else if (this$code.equals(other$code)) {
                        break label47;
                    }

                    return false;
                }

                Object this$domain = this.getDomain();
                Object other$domain = other.getDomain();
                if (this$domain == null) {
                    if (other$domain != null) {
                        return false;
                    }
                } else if (!this$domain.equals(other$domain)) {
                    return false;
                }

                Object this$message = this.getMessage();
                Object other$message = other.getMessage();
                if (this$message == null) {
                    if (other$message != null) {
                        return false;
                    }
                } else if (!this$message.equals(other$message)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof SLRunTimeError;
    }

    @Override
    public int hashCode() {
        int result = 1;
        Object $code = this.getCode();
        result = result * 59 + ($code == null ? 43 : $code.hashCode());
        Object $domain = this.getDomain();
        result = result * 59 + ($domain == null ? 43 : $domain.hashCode());
        Object $message = this.getMessage();
        result = result * 59 + ($message == null ? 43 : $message.hashCode());
        return result;
    }

    @Override
    public String toString() {
        return "SLRunTimeError(code=" + this.getCode() + ", domain=" + this.getDomain() + ", message=" + this.getMessage() + ")";
    }


    public static class SLRunTimeErrorBuilder {
        private Integer code;
        private String domain = DOMAIN_SLTEAM;
        private String message;

        SLRunTimeErrorBuilder() {
        }

        public SLRunTimeErrorBuilder code(final Integer code) {
            this.code = code;
            return this;
        }

        public SLRunTimeErrorBuilder domain(final String domain) {
            this.domain = domain;
            return this;
        }

        public SLRunTimeErrorBuilder message(final String message) {
            this.message = message;
            return this;
        }

        public SLRunTimeError build() {
            return new SLRunTimeError(this.code, domain, this.message);
        }

        @Override
        public String toString() {
            return "SLRunTimeError.SLRunTimeErrorBuilder(code=" + this.code + ", domain$value=" + this.domain + ", message=" + this.message + ")";
        }
    }
}
